package com.szq.pattern.util;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @description:
 * @author: szq
 * @date: 2021-09-09 16:58:00
 */
public class RedisUtils {

    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);

    /**
     * 库存
     */
    private AtomicInteger stock = new AtomicInteger(0);

    public RedisUtils(){
        //模拟库存消耗，一秒钟一个
        scheduledExecutorService.scheduleAtFixedRate(()->{
            stock.addAndGet(1);
        }, 0, 1000, TimeUnit.MILLISECONDS);
    }

    public int getStockUsed(){
        return stock.get();
    }

}
